//
//  HTClassThemeSmokingView.swift
//  QuitSmokingApp
//
//  Created by z on 2024/3/17.
//

import UIKit

class HTClassThemeSmokingView: UIView {
    
    lazy var var_freeView: UIView = {
        let var_bgView = UIView()
        var_bgView.isUserInteractionEnabled = true
        let var_iconImg = UIImageView()
        var_iconImg.image = UIImage(named: "icon_button_style_01")
        var_bgView.addSubview(var_iconImg)
        var_iconImg.snp.makeConstraints { make in
            make.centerY.centerX.equalToSuperview()
            make.size.equalTo(var_bgView.snp.size).offset(-30.auto())
        }
        return var_bgView
    }()
    
    lazy var var_yellowView: UIView = {
        let var_yellow = UIView()
        let var_iconImg = UIImageView()
        var_iconImg.image = UIImage(named: "icon_button_style_02")
        var_yellow.addSubview(var_iconImg)
        var_iconImg.snp.makeConstraints { make in
            make.centerY.centerX.equalToSuperview()
            make.size.equalTo(var_yellow.snp.size).offset(-30.auto())
        }
        return var_yellow
    }()

    lazy var var_purpleView: UIView = {
        let var_purple = UIView()
        let var_iconImg = UIImageView()
        var_iconImg.image = UIImage(named: "icon_button_style_03")
        var_purple.addSubview(var_iconImg)
        var_iconImg.snp.makeConstraints { make in
            make.centerY.centerX.equalToSuperview()
            make.size.equalTo(var_purple.snp.size).offset(-30.auto())
        }
        return var_purple
    }()
    
    lazy var var_redView: UIView = {
        let var_red = UIView()
        let var_iconImg = UIImageView()
        var_iconImg.image = UIImage(named: "icon_button_style_04")
        var_red.addSubview(var_iconImg)
        var_iconImg.snp.makeConstraints { make in
            make.centerY.centerX.equalToSuperview()
            make.size.equalTo(var_red.snp.size).offset(-30.auto())
        }
        return var_red
    }()
    
    lazy var var_selView: UIView = {
        let var_sel = UIView()
        var_sel.backgroundColor = UIColor("#212329")
        var_sel.layer.cornerRadius = 8.auto()
        var_sel.layer.borderWidth = 1.auto()
        var_sel.layer.borderColor = UIColor("#298CB2").cgColor
        var_sel.layer.shadowOpacity = 0.7
        var_sel.layer.shadowOffset = CGSize(width: 0, height: 1)
        var_sel.layer.shadowRadius = 6
        var_sel.layer.shadowColor = UIColor("#298CB2").cgColor
        let var_selIcon = UIImageView()
        var_selIcon.image = UIImage(named: "icon_button_sel_icon")
        var_sel.addSubview(var_selIcon)
        var_selIcon.snp.makeConstraints { make in
            make.trailing.bottom.equalToSuperview().offset(-5.auto())
            make.size.equalTo(24.auto())
        }
        return var_sel
    }()
    
    var var_selectCallback: ((_ var_index: Int,_ var_price: Int)->())?
    
    var var_selectIndex: Int = 0 {
        didSet {
            if var_selectIndex == 0 {
                var_selView.snp.remakeConstraints { make in
                    make.centerX.centerY.equalTo(var_freeView)
                    make.size.equalTo(self.snp.width).dividedBy(2)
                }
            }else if var_selectIndex == 1 {
                var_selView.snp.remakeConstraints { make in
                    make.centerX.centerY.equalTo(var_yellowView)
                    make.size.equalTo(self.snp.width).dividedBy(2)
                }
            }else if var_selectIndex == 2 {
                var_selView.snp.remakeConstraints { make in
                    make.centerX.centerY.equalTo(var_purpleView)
                    make.size.equalTo(self.snp.width).dividedBy(2)
                }
            }else{
                var_selView.snp.remakeConstraints { make in
                    make.centerX.centerY.equalTo(var_redView)
                    make.size.equalTo(self.snp.width).dividedBy(2)
                }
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        ht_initUI()
        ht_addActionHandle()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    func ht_addActionHandle(){
        var_freeView.addTapGesture { [weak self] gesture in
            self?.var_selectCallback?(0, 0)
        }
        
        var_yellowView.addTapGesture { [weak self] gesture in
            self?.var_selectCallback?(1, 20)
        }
        
        var_purpleView.addTapGesture { [weak self] gesture in
            self?.var_selectCallback?(2, 20)
        }
        
        var_redView.addTapGesture { [weak self] gesture in
            self?.var_selectCallback?(3, 20)
        }
    }
    
    func ht_initUI(){
        self.backgroundColor = UIColor("#212329")
        self.layer.cornerRadius = 8.auto()
        self.layer.borderWidth = 1.auto()
        self.layer.borderColor = UIColor("#298CB2").cgColor
        self.layer.shadowOpacity = 0.7
        self.layer.shadowOffset = CGSize(width: 0, height: 1)
        self.layer.shadowRadius = 6
        self.layer.shadowColor = UIColor("#298CB2").cgColor
        
        let var_hLine = UIView()
        var_hLine.backgroundColor = UIColor("#717171")
        self.addSubview(var_hLine)
        var_hLine.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(30.auto())
            make.trailing.equalToSuperview().offset(-30.auto())
            make.centerY.equalToSuperview()
            make.height.equalTo(1.auto())
        }
        
        let var_vLine = UIView()
        var_vLine.backgroundColor = UIColor("#717171")
        self.addSubview(var_vLine)
        var_vLine.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(30.auto())
            make.bottom.equalToSuperview().offset(-30.auto())
            make.centerX.equalToSuperview()
            make.width.equalTo(1.auto())
        }
        
        self.addSubview(var_selView)
        self.addSubview(var_freeView)
        self.addSubview(var_yellowView)
        self.addSubview(var_purpleView)
        self.addSubview(var_redView)
        
        var_selView.snp.makeConstraints { make in
            make.centerX.centerY.equalTo(var_freeView)
            make.size.equalTo(self.snp.width).dividedBy(2)
        }
        
        var_freeView.snp.makeConstraints { make in
            make.leading.top.equalToSuperview()
            make.size.equalTo(self.snp.width).dividedBy(2)
        }
        
        var_yellowView.snp.makeConstraints { make in
            make.trailing.top.equalToSuperview()
            make.size.equalTo(self.snp.width).dividedBy(2)
        }
        
        var_purpleView.snp.makeConstraints { make in
            make.leading.bottom.equalToSuperview()
            make.size.equalTo(self.snp.width).dividedBy(2)
        }
        
        var_redView.snp.makeConstraints { make in
            make.trailing.bottom.equalToSuperview()
            make.size.equalTo(self.snp.width).dividedBy(2)
        }
    }

}
